package com.lfz.demo.service.Impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lfz.demo.dao.PopulationNewsMapper;
import com.lfz.demo.repository.PopulationNewsRepository;
import com.lfz.demo.entity.PopulationNews;
import com.lfz.demo.service.PopulationNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lfz
 * @date 2025/3/5 18:16
 */
@Service
public class PopulationNewsServiceImpl extends ServiceImpl<PopulationNewsMapper, PopulationNews> implements PopulationNewsService {

    @Autowired
    private PopulationNewsMapper populationNewsMapper;

    @Autowired
    private PopulationNewsRepository populationNewsRepository;

    @Override
    public Page<PopulationNews> findByPage(Specification<PopulationNews> spec, Pageable pageable) {
        return populationNewsRepository.findAll(spec, pageable);
    }

    @Override
    public List<PopulationNews> listNewsLimit3() {
//        List<PopulationNews> populationNewsByCreateTimeTop3 = this.list(Wrappers.lambdaQuery(PopulationNews.class)
//                .orderByDesc(PopulationNews::getCreateTime)
//                .last("limit 3"));
        List<PopulationNews> populationNews = populationNewsMapper.listNewsLimit3();

        return populationNews;
    }

    @Override
    public List<PopulationNews> pastNewsListDesc() {
        return populationNewsMapper.pastNewsListDesc();
    }
}
